import React from 'react'
import fetch from 'isomorphic-fetch';
import State from './../State'

console.log('App12 is required...');

class App12 extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            age: 26,
            money: State.getMoney()
        }
    }

    testClick() {
        this.setState({
            ...this.state,
            age: this.state.age + 1
        });
    }

    buy() {
        State.buy();
        this.setState({
            ...this.state,
            money: State.getMoney()
        });
        const url = 'http://127.0.0.1:3000/number/' + State.getMoney();
        fetch(url, {credentials: 'include'}).then(response=> response.json()).then(json=> console.log(json));
    }

    render() {
        return <div>
            <div style={{color: '#f00', background: '#0f0'}} onClick={this.buy.bind(this)}>{this.state.money}</div>
            <br/>
            <div style={{color: '#0f0', background: '#f00'}} onClick={this.testClick.bind(this)}>{this.state.age}</div>
        </div>
    }
}

export default App12;